using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Linq;
using System.Linq;
using CSW.Framework.UI.Binding;
using CSW.Framework.UI.DevEx.Binding;
using CSW.Framework.UI.DevEx.Forms;

namespace CSW.Security.UI.DevEx.Forms
{
    /// <summary>
    /// SecurityRoleEditForm
    /// </summary>
    public partial class SecurityRoleEditForm : DXBaseEditForm
    {
        private readonly EditFormBinder m_Binder;
        private readonly Security_Role m_Security_Role;

        /// <summary>
        /// Initializes a new instance of the <see cref="SecurityRoleEditForm"/> class.
        /// </summary>
        public SecurityRoleEditForm(Security_Role security_Role)
        {
            InitializeComponent();

            m_Security_Role = security_Role;

            m_Binder = new EditFormBinder(this, m_Security_Role, dxError, btnSave, "Role", RecordType.Parent, ShowErrors.AfterSave);
            m_Binder.Bind(new BindableTextEdit(txtRoleID), "RoleID");
            m_Binder.Bind(new BindableTextEdit(txtDescription), "Description");
            m_Binder.UpdateControls();

            appFunctionSelectUserControl.Setup<Security_AppFunction, Security_RoleAppFunction>(
                Security_AppFunction.GetAll(),
                m_Security_Role.Security_RoleAppFunction,
                p => p.Security_AppFunction,
                (q, r) => q.AppFunctionID == r.AppFunctionID,
                s => new Security_RoleAppFunction() { Security_AppFunction = s },
                SecurityTest.DataContextInstance.Security_RoleAppFunction,
                new string[] { "ID", "Description" },
                new string[] { "AppFunctionID", "Description" },
                false,
                m_Binder
            );
        }
    }
}